|
|
CONTENTSVersion
Number Contents |
Finder 6.1 introduced version ('vers') resources as a way to allow the creator of a file to identify the version of a file, as well as the version of a set of files which includes this file. The format of this resource is described in Inside Macintosh: Macintosh Toolbox Essentials. This Note, originally Technote OV 12- Version Territory,
clarifies the format of data in the
All Mac OS programmers who distribute program files of any type should include version resources in their files. |
Version Number ContentsWhile the version resource structure is described in
Inside
Macintosh, it does not clearly describe the format for
the data in all the fields of the A The values in the The value in the Consequences of Using BCD for
|
Apple's Version Number SchemeApple uses a version numbering scheme for its software products which you might want to adopt. Table 1 summarizes the scheme, which involves three numbers, each separated by periods.
Note that Apple increments the first number when it releases a major revision, the second number when it releases a minor revision, and the third number when it releases a version to address bugs (the third number is omitted if it is zero). During product development, Apple uses a version number followed by a suffix which indicates the stage of development. Table 2 presents a few examples.
Table 2-Development Version Numbering |
Comparing Version NumbersA problem can arise when comparing version numbers by casting them to unsigned longs. When compared this way, Golden Master (GM) version numbers will compare as being older than any of the final candidate versions. For the GM release of a file, the version resource will
have the In the past, this is most often a problem during installations when installing the GM version of a package over a perviously installed final candidate version of the same package. The installer would complain that you are trying to replace newer versions of the files in the package when this is clearly not the case. The Apple installer (and most other installers) avoid this problem by comparing the individual fields of version resources. The following function will properly compare two
pascal SInt16 CompareVersions( NumVersion *vers1, NumVersion *vers2 ) { UInt16 nonRelRev1, nonRelRev2; if (vers1->majorRev > vers2->majorRev) return 1; if (vers1->majorRev < vers2->majorRev) return -1; if (vers1->minorAndBugRev > vers2->minorAndBugRev) return 1; if (vers1->minorAndBugRev < vers2->minorAndBugRev) return -1; if (vers1->stage > vers2->stage) return 1; if (vers1->stage < vers2->stage) return -1; nonRelRev1 = vers1->nonRelRev; nonRelRev2 = vers2->nonRelRev; if (vers1->stage == finalStage) { if (vers1->nonRelRev == 0) nonRelRev1 = 0xFFFF; if (vers2->nonRelRev == 0) nonRelRev2 = 0xFFFF; } if (nonRelRev1 > nonRelRev2) return 1; if (nonRelRev1 < nonRelRev2) return -1; return 0; } |
'vers' Resource StructureThe structure of a 'vers' resource is defined in
type 'vers' { hex byte; /* Major revision in BCD*/ hex byte; /* Minor revision in BCD*/ hex byte development = 0x20, /* Release stage */ alpha = 0x40, beta = 0x60, final = 0x80, /* or */ release = 0x80; hex byte; /* Non-final release # */ integer; /* Region code */ pstring; /* Short version number */ pstring; /* Long version number */ }; The structure of the corresponding struct VersRec { /* 'vers' resource format */ NumVersion numericVersion; /* encoded version number */ short countryCode; /* country code from intl utilities */ Str255 shortVersion; /* version number string - worst case */ Str255 reserved; /* longMessage string packed after shortVersion*/ }; typedef struct VersRec VersRec; typedef VersRec * VersRecPtr; typedef VersRecPtr * VersRecHndl; The structure of the struct NumVersion { /* Numeric version part of 'vers' resource */ UInt8 majorRev; /* 1st part of version number in BCD*/ UInt8 minorAndBugRev; /* 2nd & 3rd part of version number share a byte*/ UInt8 stage; /* stage code: dev, alpha, beta, final*/ UInt8 nonRelRev; /* revision level of non-released version*/ }; typedef struct NumVersion NumVersion; The structure of the union NumVersionVariant { /* NumVersionVariant is a wrapper so NumVersion can be accessed as a 32-bit value */ NumVersion parts; unsigned long whole; }; typedef union NumVersionVariant NumVersionVariant; |
Mention of third-party sites and third-party products is for informational purposes only, and constitutes neither an endorsement nor a recommendation. Apple assumes no responsibility with regard to the selection, performance, or use of these vendors or products.
|
NumVersion
structure.Thanks to Mark Cookson, Pete Gontier, and Quinn.